﻿using EasyToHelp.Business;
using EasyToHelp.DBFactory;
using EasyToHelp.Entity;
using System;
using System.Collections.Generic;
using System.Text;

namespace EasyToHelp.Service
{
    public class GoodsClassService: IGoodsClassService
    {
        #region 新增
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Add(GoodsClass model)
        {
            return DBHelper.InsertExecute<GoodsClass>(model).Id;
        }
        #endregion

        #region 更新
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Update( GoodsClass model)
        {
            return DBHelper.UpdateExecute<GoodsClass>(model);
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public int Delete(GoodsClass model)
        {
            return DBHelper.DeleteExecute<GoodsClass>(model);
        }
        #endregion

        #region 获取所有
        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        public List<GoodsClass> GetList()
        {
            using (var db = ContextHelper.Context(ContextHelper._connString))
            {
                return db.Query<GoodsClass>().ToList();
            }
        }
        #endregion

        #region 编辑
        public object Edit(GoodsClass model)
        {
            if (model.Id > 0)
            {
                if (Update(model) > 0)
                {
                    return ResultInfo.Success("编辑成功！");
                }
            }
            else
            {
                if (Add(model) > 0)
                {
                    return ResultInfo.Success("注册成功！");
                }
            }
            return ResultInfo.Error("注册失败！");
        }
        #endregion
    }
}
